package com.foreknow.service.impl;

import com.foreknow.dao.SchedulingDao;
import com.foreknow.dao.SchedulingMapper;
import com.foreknow.entity.Scheduling;
import com.foreknow.entity.SchedulingExample;
import com.foreknow.service.SchedulingService;
import io.swagger.annotations.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Transactional
@Service
public class SchedulingServiceImpl implements SchedulingService {
    @Autowired
    private SchedulingDao schedulingDao;
    @Autowired
    private SchedulingMapper schedulingMapper;


    //    排班首页专用的联合结果查询
    @Override
    public List<Scheduling> querySchedulingForAll() throws Exception {
        return schedulingDao.querySchedulingForAll();
    }

    @Override
    public List<Scheduling> querySchedulingForAll_inCurrentPage(String startdate, String enddate, Integer pageSize, Integer currentPage) throws Exception {
        Integer start = (currentPage - 1) * pageSize;
        Integer offset = pageSize;
        return schedulingDao.querySchedulingForAll_inCurrentPage(startdate, enddate, start, offset);
    }

    @Override
    public int countBySchedulingExample(Date start, Date end) throws Exception {
        SchedulingExample example = new SchedulingExample();
        SchedulingExample.Criteria criteria = example.createCriteria();
        if (start != null && end != null) {
            criteria.andScheddateBetween(start, end);
        }

        return schedulingMapper.countByExample(example);
    }

    @Override
    public int updateScheduling(Scheduling scheduling) throws Exception {
        return 0;
    }

    @Override
    public int addScheduling(Scheduling scheduling) throws Exception {
        schedulingMapper.insertSelective(scheduling);
        return 0;
    }


    @Override
    public List<Scheduling> querySchedulingByTimeAndUserId(Date start, Date end, Integer userId) throws Exception {
        SchedulingExample example = new SchedulingExample();
        SchedulingExample.Criteria criteria = example.createCriteria();
        criteria.andScheddateBetween(start, end);
        criteria.andUseridEqualTo(userId);
        return schedulingMapper.selectByExample(example);
    }

    @Override
    public int deleteScheduling(Integer id) throws Exception {
        return 0;
    }
}
